<template>
	<view class="my-collect">
		<bs-navbar title='我的信息'></bs-navbar>
		<u-sticky :offset-top='navHeight'>
			<u-tabs active-color='#0050A5' inactive-color='#9A9A9A' :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
		</u-sticky>

		<bs-gap top="0" bottom="0"></bs-gap>
		<bsTextImgList :onMsg='"暂无信息"' @handDetails='handDetails' :list='infoList' :status='status'></bsTextImgList>
	</view>
</template>

<script>
	import bsTextImgList from '@/components/bs-text-img-list/bs-text-img-list.vue'
	export default {
		components: {
			bsTextImgList
		},
		data() {
			return {
				navHeight: this.CustomBar * 2,
				list: [{
					name: '全部',
					readMessage: ''
				}, {
					name: '已读',
					readMessage: 1
				}, {
					name: '未读',
					readMessage: 0
				}],
				current: 0,
				pages: 0,
				status: 'nomore',
				paging: {
					page: 1,
					pageSize: 10,
					readMessage: ''
				},
				infoList: []
			};
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		async onReachBottom() {
			await this.getMore()
		},
		async onLoad() {
			await this.init()
			// findUnreadNumber
		},
		methods: {
			async handDetails(item) {
				if (!item.readMessage) {
					let res = await this.$u.api.addReadMessage({
						messageId: item.messageId
					})
				}
				console.log(item)
				this.init()
				if (item.url) {
					uni.navigateTo({
						url: '/pages/webView/webView?webSrc=' + item.url
					})
				}

			},
			async getMore() {
				if (this.pages == this.paging.page) {
					this.status = 'nomore';
					return
				}
				this.status = 'loading';
				this.paging.page = ++this.paging.page;
				let infoList = []
				infoList = await this.$u.api.findSystemMessageListUser(this.paging)
				this.pages = infoList.pages
				this.infoList = this.infoList.concat(infoList.list)
				this.status = 'loadmore';
			},
			//我参加的
			async init() {
				this.paging.page = 1
				let res = await this.$u.api.findSystemMessageListUser(this.paging)
				this.pages = res.pages
				this.infoList = res.list
				let noMsg = await this.$u.api.findUnreadNumber()
				console.log(this.infoList, noMsg)
				this.list[2].name = "未读(" + noMsg + ")"
			},
			async change(index) {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
				this.paging.readMessage = this.list[index].readMessage
				this.current = index;
				await this.init()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.my-collect {}
</style>
